<template>
    <div>
        <div>
            <el-form :inline="true" :model="formInline" class="demo-form-inline">
                <el-form-item label="架次">
                    <el-input style="width:100px" size="mini" v-model="formInline.planeNo" placeholder="架次"></el-input>
                </el-form-item>
                <el-form-item label="图号">
                    <el-input style="width:120px" size="mini" v-model="formInline.itemCode" placeholder="图号"></el-input>
                </el-form-item>
                <el-form-item label="质量编号">
                    <el-input style="width:120px" size="mini" v-model="formInline.qualityCode" placeholder="质量编号"></el-input>
                </el-form-item>
                <el-form-item label="AO号">
                    <el-input style="width:120px" size="mini" v-model="formInline.aoCode" placeholder="AO号"></el-input>
                </el-form-item>
                <el-form-item label="是否配送">
                    <el-select style="width:120px" v-model="formInline.isSend" size="mini" placeholder="是否配送">
                        <el-option label="所有" value=""></el-option>
                        <el-option label="未配送" value="未配送"></el-option>
                        <el-option label="已配送" value="已配送"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item>
                    <el-button size="mini" type="primary" @click="doQuery">查询</el-button>
                    <el-button size="mini" type="primary" @click="updateRemark">修改备注</el-button>
                    
                    <el-button size="mini" type="primary" @click="cancelUndelivery">撤销未移交</el-button>
                    <el-button size="mini" type="primary" @click="reSend">重新配送</el-button>
                    <el-button size="mini" type="primary" @click="reSendRemark">推送备注</el-button>
                    <el-button size="mini" type="primary" @click="cancelDelivery">撤销配送</el-button>
                </el-form-item>
            </el-form>
        </div>
        <el-table  ref="receiveTable" size="mini" border  :data="resData" @selection-change="handleSelectionChange"  height="550" >
            <el-table-column type="selection" width="80" :show-overflow-tooltip="true"> </el-table-column>
            <el-table-column type="index" label="序号" width="80" :show-overflow-tooltip="true"> </el-table-column>
            <el-table-column prop="deliveryStatus" width="100" label="交接单状态" :show-overflow-tooltip="true"> </el-table-column>
            <el-table-column prop="aoCode" label="AO号" width="180" :show-overflow-tooltip="true"> </el-table-column>
            <el-table-column prop="itemCode" label="图号" width="180" :show-overflow-tooltip="true"> </el-table-column>
            <el-table-column prop="mProductNumber" label="型号" width="140" :show-overflow-tooltip="true"> </el-table-column>
            <el-table-column prop="qualityCode" label="质量编号" width="140" :show-overflow-tooltip="true" > </el-table-column>
            <el-table-column prop="deliveryQty" label="数量" :show-overflow-tooltip="true"> </el-table-column>
            <el-table-column prop="planeNo" label="架次" :show-overflow-tooltip="true"> </el-table-column>
            <el-table-column prop="repartAss" label="装配图号" :show-overflow-tooltip="true"> </el-table-column>
            <el-table-column prop="mesCheckQualiticationId" label="合格证号" width="150" :show-overflow-tooltip="true"></el-table-column>
            <el-table-column prop="toolCode" label="托盘号" :show-overflow-tooltip="true"> </el-table-column>
            <el-table-column prop="receiveRemark" label="备注" :show-overflow-tooltip="true"> </el-table-column>
            <el-table-column prop="carCode" label="小车码" width="180" :show-overflow-tooltip="true"> </el-table-column>
            <el-table-column prop="creationDate" label="创建时间" width="180" :show-overflow-tooltip="true"> </el-table-column>
            <el-table-column prop="msAoMatchBillId" label="matchBill表主键" width="180" :show-overflow-tooltip="true"> </el-table-column>
            <el-table-column prop="msAoMatchInfoId" label="matchInfo表主键" width="180" :show-overflow-tooltip="true"> </el-table-column>
            <el-table-column prop="deliveryPlanCode" label="组号(groupCode)" width="180" :show-overflow-tooltip="true"> </el-table-column>
            <el-table-column prop="wmsDeliveryPlanId" label="交接单主键"  width="180" :show-overflow-tooltip="true"> </el-table-column>
            <el-table-column prop="erpWmsDeliveryPlanId" label="ERP交接单主键"  width="180" :show-overflow-tooltip="true"> </el-table-column>
        </el-table>
        <!-- 分页 -->
        <el-pagination  @size-change="handleSizeChange"  @current-change="handleCurrentChange"  :current-page="pageNumber"
        :page-sizes="[20,50,100,500]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="totalCount">
        </el-pagination>
    </div>
</template>
<script>
import request from "@/utils/request.js";
export default {
    name:"ImIqTopTable",
    data(){
        return{
             // 当前页数
            pageNumber: 1,
            // 数据总个数
            totalCount: 0,
            // 返回的数据数组
            resData: [],
            selectData:[],
            // 每页数据个数
            pageSize: 20,
            // 确认列表高亮参数
            stableIndex: 0,
            formInline:{planeNo:"",itemCode:"",aoCode:"",qualityCode:""}
        }
    },
    methods:{
        // 每页个数改变
        handleSizeChange(val){
            this.pageSize = val
            this.$options.methods.doQuery.bind(this)();
        },
        // 页数改变
        handleCurrentChange(val) {
            this.pageNumber = val;
            this.$options.methods.doQuery.bind(this)();
        },
        handleSelectionChange(val){
            this.selectData = val;
        },
        doQuery(){
            request.post("/DeliveryPlanQuery/DeliveryQuery",{"queryParam":this.formInline,
                "page":{"currentPage":this.pageNumber,"pageSize":this.pageSize}}).then((res)=>{
                console.log("res",res);
                this.resData = res.data.list;
                this.totalCount = res.data.total;
            })
        },
        cancelDelivery(){
            if(this.selectData.length==0){
                this.$Alert({title:"失败",type:"error",message:"请至少选择一条数据"})
                return ;
            }
            var message = "";
            var A = Math.ceil(Math.random()*100);
            var B = Math.ceil(Math.random()*10);
            var C = Math.ceil(Math.random()*100);
            var D = Math.ceil(Math.random()*100);
            message = "请将 "+A+"/"+B+"+"+C+"%"+D+" 计算的结果输入到输入框中!";
            console.log(Math.floor(A/B)+"============"+C%D);
            var result = Math.floor(A/B)+C%D;
            this.$prompt(message,"提示",{ 
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'}
            ).then(({value})=>{
                console.log("value",value);
                console.log("result",result);
                if(result != value){
                    this.$Alert({type:"error",title:"成功",message:"计算的结果不对"});
                    return;
                }
                request.post("/DeliveryPlanQuery/cancelDelivery",this.selectData).then((res)=>{
                console.log("res",res);
                if(res.data.retCode=="200"){
                    this.$Alert({type:"success",title:"成功",message:res.data.message});
                }else{
                    this.$Alert({type:"error",title:"成功",message:res.data.message});
                }
            })
            });
            
        },
        reSend(){//推送交接单
            if(this.selectData.length==0){
                this.$Alert({title:"失败",type:"error",message:"请至少选择一条数据"})
                return ;
            }
            for(var i=0;i<this.selectData.length;i++){
                if(this.selectData[i].deliveryStatus=="10"||this.selectData[i].deliveryStatus=="11"){
                    this.$Alert({title:"失败",type:"error",message:"只能选择交接单状态为1,2,3的数据"})
                    return ;
                }
            }
            this.$confirm("确定是否重新推送！！！","提示",{ 
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'}
            ).then(()=>{
                    request.post("/DeliveryPlanQuery/reSend",this.selectData).then((res)=>{
                    console.log("res",res);
                    if(res.data.retCode=="200"){
                        this.$Alert({type:"success",title:"成功",message:res.data.message});
                    }else{
                        this.$Alert({type:"error",title:"成功",message:res.data.message});
                    }
                })
            });
        },
        reSendRemark(){//推送备注
            if(this.selectData.length==0){
                this.$Alert({title:"失败",type:"error",message:"请至少选择一条数据"})
                return ;
            }
            for(var i=0;i<this.selectData.length;i++){
                if(this.selectData[i].deliveryStatus=="10"||this.selectData[i].deliveryStatus=="11"){
                    this.$Alert({title:"失败",type:"error",message:"只能选择交接单状态为1,2,3的数据"})
                    return ;
                }
            }
            this.$confirm("确定是否推送备注！！！","提示",{ 
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'}
            ).then(()=>{
                    request.post("/DeliveryPlanQuery/reSendRemark",this.selectData).then((res)=>{
                    console.log("res",res);
                    if(res.data.retCode=="200"){
                        this.$Alert({type:"success",title:"成功",message:res.data.message});
                    }else{
                        this.$Alert({type:"error",title:"成功",message:res.data.message});
                    }
                })
            });
        },
        updateRemark(){//修改备注
            if(this.selectData.length!=1){
                this.$Alert({title:"失败",type:"error",message:"请选择一条数据"})
                return ;
            }
            this.$prompt('请输入备注', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消'
            }).then(({ value }) => {
                var row = this.selectData[0];
                row.receiveRemark = value;
                request.post("/DeliveryPlanQuery/updateRemark",row).then((res)=>{
                if(res.data.retCode=="200"){
                    this.$Alert({type:"success",title:"成功",message:res.data.message});
                }else{
                    this.$Alert({type:"error",title:"失败",message:res.data.message});
                }
                });

            }).catch(() => {});
        },
        cancelUndelivery(){
            if(this.selectData.length==0){
                this.$Alert({title:"失败",type:"error",message:"请至少选择一条数据"})
                return ;
            }
            request.post("/DeliveryPlanQuery/cancelUnDelivery",this.selectData).then((res)=>{
                console.log("res",res);
                if(res.data.retCode=="200"){
                    this.$Alert({type:"success",title:"成功",message:res.data.message});
                }else{
                    this.$Alert({type:"error",title:"成功",message:res.data.message});
                }
            })
        }
    },
    mounted() {

    }
}
</script>
<style scoped>
</style>